package com.rgs.module.login.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.rgs.base.core.model.WebApiReturnResultModel;
import com.rgs.model.login.dto.request.SubmitUserDTO;
import com.rgs.module.login.entity.SysUserDO;
import com.rgs.module.login.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Ren Gaoshuai
 * @ClassName SysUserController
 * @date 2021-12-27 22:02
 **/
@RestController
@RequestMapping("/v1/sysUser")
public class SysUserController {

    @Resource
    SysUserService sysUserService;

    @ApiOperation("用户注册")
    @PostMapping("/submit")
    public WebApiReturnResultModel<String> submit(@RequestBody @Validated SubmitUserDTO submitUser) {
        SysUserDO sysUserDO = BeanUtil.copyProperties(submitUser, SysUserDO.class);
        if (StrUtil.isEmpty(sysUserDO.getId())) {
            // 新增
            sysUserService.insert(sysUserDO);
        } else {
            // 更新
            sysUserService.update(sysUserDO);
        }
        return WebApiReturnResultModel.ofSuccess(sysUserDO.getId());
    }
}
